16 #ifdef __MSP430_HAS_EUSCI_Ax__
21 void EUSCI_A_SPI_initMaster (uint16_t baseAddress,
22 EUSCI_A_SPI_initMasterParam *
param)
25 HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
28 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCCKPH + UCCKPL + UC7BIT + UCMSB +
29 UCMST + UCMODE_3 + UCSYNC);
32 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSSEL_3);
35 HWREG16(baseAddress + OFS_UCAxCTLW0) |= (uint16_t)
param->selectClockSource;
37 HWREG16(baseAddress + OFS_UCAxBRW) =
38 (uint16_t)(
param->clockSourceFrequency /
param->desiredSpiClock);
47 HWREG16(baseAddress + OFS_UCAxCTLW0) |= (
50 param->clockPolarity +
56 HWREG16(baseAddress + OFS_UCAxMCTLW) = 0;
59 void EUSCI_A_SPI_select4PinFunctionality (uint16_t baseAddress,
60 uint16_t select4PinFunctionality
63 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCSTEM;
64 HWREG16(baseAddress + OFS_UCAxCTLW0) |= select4PinFunctionality;
67 void EUSCI_A_SPI_changeMasterClock (uint16_t baseAddress,
68 EUSCI_A_SPI_changeMasterClockParam *
param)
71 HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
73 HWREG16(baseAddress + OFS_UCAxBRW) =
74 (uint16_t)(
param->clockSourceFrequency /
param->desiredSpiClock);
77 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSWRST);
80 void EUSCI_A_SPI_initSlave (uint16_t baseAddress, EUSCI_A_SPI_initSlaveParam *
param)
83 HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
86 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCMSB +
95 HWREG16(baseAddress + OFS_UCAxCTLW0) |= (
param->clockPhase +
96 param->clockPolarity +
103 void EUSCI_A_SPI_changeClockPhasePolarity (uint16_t baseAddress,
105 uint16_t clockPolarity
109 HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
111 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCCKPH + UCCKPL);
113 HWREG16(baseAddress + OFS_UCAxCTLW0) |= (
119 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSWRST);
122 void EUSCI_A_SPI_transmitData ( uint16_t baseAddress,
129 uint8_t EUSCI_A_SPI_receiveData (uint16_t baseAddress)
131 return (
HWREG16(baseAddress + OFS_UCAxRXBUF)) ;
134 void EUSCI_A_SPI_enableInterrupt (uint16_t baseAddress,
138 HWREG16(baseAddress + OFS_UCAxIE) |= mask;
141 void EUSCI_A_SPI_disableInterrupt (uint16_t baseAddress,
145 HWREG16(baseAddress + OFS_UCAxIE) &= ~mask;
148 uint8_t EUSCI_A_SPI_getInterruptStatus (uint16_t baseAddress,
152 return (
HWREG16(baseAddress + OFS_UCAxIFG) & mask );
155 void EUSCI_A_SPI_clearInterrupt (uint16_t baseAddress,
159 HWREG16(baseAddress + OFS_UCAxIFG) &= ~mask;
162 void EUSCI_A_SPI_enable (uint16_t baseAddress)
165 HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSWRST);
168 void EUSCI_A_SPI_disable (uint16_t baseAddress)
171 HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
174 uint32_t EUSCI_A_SPI_getReceiveBufferAddress (uint16_t baseAddress)
176 return ( baseAddress + OFS_UCAxRXBUF );
179 uint32_t EUSCI_A_SPI_getTransmitBufferAddress (uint16_t baseAddress)
181 return ( baseAddress + OFS_UCAxTXBUF );
184 uint16_t EUSCI_A_SPI_isBusy (uint16_t baseAddress)
187 return (
HWREG16(baseAddress + OFS_UCAxSTATW) & UCBUSY);
MPU_initThreeSegmentsParam param